/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-12-16
 * @Time  : 下午8:41
 * @brief :
 */
(function () {
    var Check = require('common:widget/ui/base/check.js').Check,
        $page = $('.page-forgetstep1'),
        $phone = $page.find('.phone'),
        $qcode = $page.find('.qcode'),
        $errorTip = $page.find('.error-tip'),
        $btnConfirm = $page.find('.btn-confirm'),
        check;

    check = new Check({
        '$qcode':$qcode,
        '$phone':$phone,
        '$tip':$errorTip
    });

    $btnConfirm.click(function(){
        var me = this;
        $errorTip.css('visibility','hidden');
        if(!$(this).hasClass('btn-disable')){
            if(check.check()){
                $(me).addClass('btn-disable');
                $.post('/account/preresetpassword',{
                    'user_name': $.trim($phone.val()),
                    'qcode': $.trim($qcode.val())
                },function(ret,status){
                    if(ret.error_no == 0){
                        location.href="/account/forgeting?phone="+$.trim($phone.val());
                    }else{
                        $errorTip.css('visibility','visible').text(ret.error_message);
                        $(me).removeClass('btn-disable');
                        $('.widget-gcode .btn-refresh').trigger('click');
                    }
                },'json');
            }
        }
    });
})();